package com.ruicar.afs.cloud.channel.channelworkflow.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.channel.affiliation.condition.AffiliationCondition;
import com.ruicar.afs.cloud.channel.channelworkflow.condition.ChannelOnlineWorkFlowCondition;
import com.ruicar.afs.cloud.channel.channelworkflow.entity.WorkTaskApproveRecord;
import com.ruicar.afs.cloud.channel.channelworkflow.mapper.WorkTaskApproveRecordMapper;
import com.ruicar.afs.cloud.channel.channelworkflow.service.WorkTaskApproveRecordService;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.response.FlowCmdBean;
import org.springframework.stereotype.Service;

/**
 * @author mingzhi.li
 */
@Service
public class WorkTaskApproveRecordServiceImpl extends ServiceImpl<WorkTaskApproveRecordMapper, WorkTaskApproveRecord> implements WorkTaskApproveRecordService {

    @Override
    public void startSave(String flowName, String bizDataId) {
        WorkTaskApproveRecord record = new WorkTaskApproveRecord();
        record.setBizDataId(bizDataId);
        record.setApprovalOpinion("start");
        record.setApprovalOpinionDescribe(flowName);
        this.save(record);
    }

    @Override
    public void startApproveSave(ChannelOnlineWorkFlowCondition condition) {
        WorkTaskApproveRecord record = new WorkTaskApproveRecord();
        record.setBizDataId(condition.getBizDataId());
        record.setApprovalOpinion("start");
        record.setApprovalOpinionDescribe(condition.getFlowName());
        record.setBusinessKey(condition.getBusinessKey());
        record.setBusinessType(condition.getBusinessType());
        this.save(record);
    }

    @Override
    public void approveSave(ChannelOnlineWorkFlowCondition condition, FlowCmdBean cmd) {
        WorkTaskApproveRecord record = new WorkTaskApproveRecord();
        record.setBizDataId(condition.getBizDataId());
        record.setApprovalOpinion(condition.getApprove());
        record.setApprovalOpinionDescribe(cmd.getCmdDis());
        record.setRemark(condition.getRemark());
        record.setTaskName(condition.getTaskName());
        record.setBackOpinion(condition.getBackOpinion());
        record.setBusinessKey(condition.getBusinessKey());
        record.setBusinessType(condition.getBusinessType());
        this.save(record);
    }

    @Override
    public void approveAffiliationSave(AffiliationCondition condition, FlowCmdBean cmd) {
        WorkTaskApproveRecord record = new WorkTaskApproveRecord();
        record.setBizDataId(condition.getBizDataId());
        record.setApprovalOpinion(condition.getStatus());
        record.setApprovalOpinionDescribe(cmd.getCmdDis());
        record.setRemark(condition.getExamineRemark());
        record.setTaskName(condition.getTaskName());
        record.setBackOpinion(condition.getExamineReason());
        this.save(record);
    }
}
